//
//  Home_MenuItem.swift
//  jingxin
//
//  Created by Yuki on 2020/8/7.
//  Copyright © 2020 Zl. All rights reserved.
//

import UIKit

class Home_MenuItem: UICollectionViewCell {
    lazy var textLb = UILabel();
    lazy var redView = UIView();
    
    
    override init(frame: CGRect) {
        super.init(frame: frame);
        buildUI();//创建界面
    }
    required init?(coder: NSCoder) {
        super.init(coder: coder);
        buildUI();//创建界面
    }
    
    
    //MARK:创建界面
    private func buildUI(){
        self.contentView.backgroundColor = .clear;
        /**  红色  **/
        self.redView = UIView.init();
        self.redView.backgroundColor = Color(0xFE5D27, 1);
        self.redView.layer.cornerRadius = 7.0*height();
        self.redView.layer.masksToBounds = true;
        self.redView.isHidden = true;
        self.contentView.addSubview(self.redView);
        self.redView.snp_makeConstraints { (make) in
            make.size.equalTo(CGSize(width: 14*width(), height: 14*height()));
            make.right.top.equalTo(self.contentView).offset(0);
        }
        
        /**  文字  **/
        self.textLb = UILabel.init();
        self.textLb.textAlignment = .left;
        self.textLb.font = .systemFont(ofSize: 18*height(), weight: .semibold);
        self.textLb.textColor = Color(0x121212, 1);
        self.contentView.addSubview(self.textLb);
        self.textLb.snp_makeConstraints { (make) in
            make.left.equalTo(self.contentView.snp_left).offset(0);
            make.size.equalTo(CGSize(width: 40*width(), height: 24*height()));
            make.top.equalTo(self.contentView.snp_top).offset(0);
        }
    }
    
    //MARK:设置标题
    var titleStr:String?{
        didSet{
            self.textLb.text = titleStr;
        }
    }
    
    //MARK:是否选中
    override var isSelected:Bool{
        didSet{
            self.redView.isHidden = !isSelected;
            if isSelected{
                /**  选中则修改样式  **/
                self.textLb.textColor = Color(0x121212, 1);
            }else{
                self.textLb.textColor = Color(0x666666, 1);
            }
        }
    }
}
